﻿using System;

using Rarous.TexyNet;

using Xunit;

namespace Rarous.TexyNet.Test {

  /// <summary>
  /// This is a test class for ReferenceSpec and is intended
  /// to contain all ReferenceSpec Unit Tests
  /// </summary>
  public class ReferenceSpec {

    private Reference GetReference() {
      string name = "texy";
      string url = "http://www.texy.info/";
      string title = "Texy!";
      string tooltip = "Texy! je sexy!";
      return new Reference(name, url, title, tooltip);
    }

    private Reference GetImageReference() {
      return new ImageReference("texy logo", "http://www.texy.info/logo.gif", "Texy!");
    }

    /// <summary>
    /// A test for UrlTest
    /// </summary>
    [Fact]
    public void Reference_Url_PropertyBehavior() {
      Reference target = GetReference();
      string expected = String.Empty;
      target.Url = expected;

      Assert.Equal(expected, target.Url);

      expected = "http://www.texy.info/";
      target.Url = expected;

      Assert.Equal(expected, target.Url);
    }

    /// <summary>
    /// A test for TitleTest
    /// </summary>
    [Fact]
    public void Reference_Title_PropertyBehavior() {
      Reference target = GetReference();
      string expected = String.Empty;
      target.Title = expected;

      Assert.Equal(expected, target.Title);

      expected = "Texy!";
      target.Title = expected;

      Assert.Equal(expected, target.Title);
    }


    /// <summary>
    /// A test for NameTest
    /// </summary>
    [Fact]
    public void Reference_Name_PropertyBehavior() {
      Reference target = GetReference();
      string expected = String.Empty;
      target.Name = expected;

      Assert.Equal(expected, target.Name);

      expected = "texy";
      target.Name = expected;

      Assert.Equal(expected, target.Name);
    }

    /// <summary>
    /// A test for ModifierSpec
    /// </summary>
    [Fact]
    public void Reference_Modifier_Initialized() {
      Reference target = GetReference();

      Assert.NotNull(target.Modifier);
    }

    /// <summary>
    /// A test for ToStringTest
    /// </summary>
    [Fact]
    public void Reference_ToString() {
      Reference target = GetReference();
      string expected = "[texy]: http://www.texy.info/ Texy! .(Texy! je sexy!)";

      Assert.Equal(expected, target.ToString());

      target.Name = null;
      target.Url = null;

      Assert.Equal(String.Empty, target.ToString());
    }

    /// <summary>
    /// A test for ReferenceConstructorTest2
    /// </summary>
    [Fact]
    public void Reference_Constructor_NameUrl() {
      string name = "texy";
      string url = "http://www.texy.info/";
      Reference target = new Reference(name, url);

      Assert.Equal(name, target.Name);
      Assert.Equal(url, target.Url);
      Assert.Equal(String.Empty, target.Title);
      Assert.NotNull(target.Modifier);
    }

    /// <summary>
    /// A test for ReferenceConstructorTest1
    /// </summary>
    [Fact]
    public void Reference_Constructor_NameUrlTitle() {
      string name = "texy";
      string url = "http://www.texy.info/";
      string title = "Texy!";
      Reference target = new Reference(name, url, title);

      Assert.Equal(name, target.Name);
      Assert.Equal(url, target.Url);
      Assert.Equal(title, target.Title);
      Assert.NotNull(target.Modifier);
    }

    /// <summary>
    /// A test for ReferenceConstructorTest
    /// </summary>
    [Fact]
    public void Reference_Constructor_NameUrlTitleToolTip() {
      string name = "texy";
      string url = "http://www.texy.info/";
      string title = "Texy!";
      string tooltip = "Texy! je sexy!";
      Reference target = new Reference(name, url, title, tooltip);

      Assert.Equal(name, target.Name);
      Assert.Equal(url, target.Url);
      Assert.Equal(title, target.Title);
      Assert.NotNull(target.Modifier);
      Assert.Equal(tooltip, target.Modifier.ToolTip);
    }

    [Fact]
    public void ImageReference_ToString() {
      string expected = "[*texy logo*]: http://www.texy.info/logo.gif .(Texy!)";
      Reference target = GetImageReference();

      string actual = target.ToString();
      Assert.Equal(expected, actual);
    }
  }
}
